package com.jxau.mall.user.controller;

import com.jxau.mall.common.util.ResponseVO;
import com.jxau.mall.user.entity.UserInfo;
import com.jxau.mall.user.service.IUserService;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: shop
 * @description: 用户注册控制器类
 * @author: guojiani
 * @create: 2025-04-24 20:20
 **/
@RestController
@RequestMapping("/user")
public class UserInfoController {
    @Autowired
    private IUserService userService;
    @PostMapping("/register")
    public ResponseVO register(@RequestBody UserInfo userInfo){
        // 密码加密
        String hashpw = BCrypt.hashpw(userInfo.getPassword(),BCrypt.gensalt());
        userInfo.setPassword(hashpw);
        // 保存到数据表
        userService.save(userInfo);
        return ResponseVO.success();
    }

    @PutMapping("/update")
    public ResponseVO update(@RequestBody UserInfo userInfo){
        userService.updateById(userInfo);
        return ResponseVO.success();
    }
}
